﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Dropthings.Widget.Framework;
using Dropthings.Widget.Widgets;
using Dropthings.Widget.Widgets.FusionCharts;
using Dropthings.Util;
using Dropthings.Business.Facade;
using Dropthings.Data;
using Dropthings.Model;

public partial class Widgets_FusionChart_LineWidget : System.Web.UI.UserControl, IWidget
{
    #region Fields

    private IWidgetHost _Host;


    private UserSetup _Setup
    {
        get { return Context.Items[typeof(UserSetup)] as UserSetup; }
        set { Context.Items[typeof(UserSetup)] = value; }
    }

    #endregion Fields

    #region Methods

    void IEventListener.AcceptEvent(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

    void IWidget.Closed()
    {
    }

    void IWidget.Collasped()
    {
    }

    void IWidget.Expanded()
    {
    }

    void IWidget.HideSettings(bool userClicked)
    {
        SettingsPanel.Visible = false;
    }

    void IWidget.Init(IWidgetHost host)
    {
        this._Host = host;
    }

    void IWidget.Maximized()
    {
       
    }

    void IWidget.Restored()
    {
    }

    void IWidget.ShowSettings(bool userClicked)
    {
        SettingsPanel.Visible = true;
    }
    FusionLineChart lineChart = new FusionLineChart();
    protected void Page_Load(object sender, EventArgs e)
    {
        lineChart.caption = "标题";
        lineChart.subCaption = "";
        lineChart.xAxisName = "X轴";
        lineChart.yAxisName = "Y轴";
        string chartHtml = lineChart.CreateSetElement(BuildData(), FusionLineChart.Line2D, divLineChart.ClientID, false, "", "name", "value", "text", "id", "", true, 370, 247);
        divLineChart.InnerHtml = chartHtml;
    }


    protected void LinkBtn_Clicked(object sender, EventArgs e)
    {
        var facade = Services.Get<Facade>();
        {
            var page = facade.CreateTab(Resources.SharedResources.NewTabTitle, 0);
            RedirectToTab(page);
        }
    }

    public void RedirectToTab(Tab page)
    {
        string s = _Setup.CurrentUserId.ToString();
        if (!page.IsLocked || _Setup.CurrentUserId == page.AspNetUser.UserId)
        {
            Response.Redirect("Default.aspx?" + Server.UrlEncode(page.UserTabName));
        }
        else
        {
            Response.Redirect("Default.aspx?" + Server.UrlEncode(page.LockedTabName));
        }
    }

    private DataTable BuildData()
    {
        //DataTable dtChart, string nameField, string valueField, string hoverTextField, string urlField, string urlPrefix, int chartWidth, int chartHeight

        DataTable dtData = new DataTable();

        dtData.Columns.Add("name");
        dtData.Columns.Add("value");
        dtData.Columns.Add("text");
        dtData.Columns.Add("id");

        DataRow drData = null;

        drData = dtData.NewRow();

        drData["name"] = "name51";
        drData["value"] = "51";
        drData["text"] = "text51";
        drData["id"] = "";

        dtData.Rows.Add(drData);


        drData = dtData.NewRow();

        drData["name"] = "name32";
        drData["value"] = "32";
        drData["text"] = "text52";
        drData["id"] = "52";
        dtData.Rows.Add(drData);

        drData = dtData.NewRow();

        drData["name"] = "name69";
        drData["value"] = "69";
        drData["text"] = "text69";
        drData["id"] = "69";
        dtData.Rows.Add(drData);

        drData = dtData.NewRow();

        drData["name"] = "name22";
        drData["value"] = "0";
        drData["text"] = "text22";
        drData["id"] = "22";
        dtData.Rows.Add(drData);

        drData = dtData.NewRow();

        drData["name"] = "name51";
        drData["value"] = "51";
        drData["text"] = "text51";
        drData["id"] = "0";
        dtData.Rows.Add(drData);

        drData = dtData.NewRow();

        drData["name"] = "name202";
        drData["value"] = "202";
        drData["text"] = "text202";
        drData["id"] = "202";
        dtData.Rows.Add(drData);

        return dtData;
    }
    #endregion Methods
}